package com.design.boot.service.impl;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.design.boot.mapper.mytest.BookMapper;
import com.design.boot.model.Book;
import com.design.boot.service.BookService;
/**
 * @description
 * @author kakayubei
 * @date 2021/7/31 18:03
 */
@Service
@CacheConfig(cacheNames = "BooksCache")
public class BookServiceImpl implements BookService{

    @Resource
    private BookMapper bookMapper;

    @Override
    @CacheEvict(key = "#id")
    public int deleteByPrimaryKey(Integer id) {
        return bookMapper.deleteByPrimaryKey(id);
    }

    @Override
    @CachePut(key = "#book.id")
    public int insert(Book book) {
        return bookMapper.insert(book);
    }

    @Override
    @CachePut(key = "#book.id")
    public int insertSelective(Book book) {
        return bookMapper.insertSelective(book);
    }

    @Override
    @Cacheable
    public Book selectByPrimaryKey(Integer id) {
        return bookMapper.selectByPrimaryKey(id);
    }

    @Override
    @CachePut(key = "#book.id")
    public int updateByPrimaryKeySelective(Book book) {
        return bookMapper.updateByPrimaryKeySelective(book);
    }

    @Override
    @CachePut(key = "#book.id")
    public int updateByPrimaryKey(Book book) {
        return bookMapper.updateByPrimaryKey(book);
    }

}
